package org.springframework.amqp.tutorials.config.headers;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HeaderSend {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send1(String msg) {
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("queue", "queue1");
        messageProperties.setHeader("bindType", "whereAll");
        Message message = new Message(msg.getBytes(), messageProperties);
        System.out.println("发送消息：" + msg);
        rabbitTemplate.convertAndSend(HeaderExchangeConfig.HEADER_EXCHANGE, null, message);
    }

    public void send2(String msg) {
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("queue", "queue2");
        messageProperties.setHeader("bindType", "whereAny");
        Message message = new Message(msg.getBytes(), messageProperties);
        System.out.println("发送消息：" + msg);
        rabbitTemplate.convertAndSend(HeaderExchangeConfig.HEADER_EXCHANGE, null, message);
    }

}